package com.account.book.common.response;

/**
 * @author liang-hw
 * @className ResultUtils
 * @description 返回信息工具类
 * @date 2023/11/08 13:19:52
 */
public class ResultUtils {

    /**
     * @param @param t
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description 成功时生成result的方法,有返回数据
     * @date 2023/11/08 13:19:46
     */
    public static <T> BaseResult<T> success(T t) {
        BaseResult<T> result = new BaseResult<>();
        result.setStatus(ResultEnum.SUCCESS.getCode());
        result.setMessage(ResultEnum.SUCCESS.getMessage());
        result.setData(t);
        return result;
    }

    /**
     * @param
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description 成功时生成result的方法,无返回数据
     * @date 2023/11/08 13:19:35
     */
    public static <T> BaseResult<T> success() {
        return success(null);
    }

    /**
     * @param @param message
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description  成功时生成result的方法,无返回数据
     * @date 2023/11/08 13:19:28
     */
    public static <T> BaseResult<T> success(String message) {
        return successMessage(message);
    }


    /**
     * @param @param status
     * @param msg
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description 成功时生成result的方法,有返回数据
     * @date 2023/11/08 13:19:16
     */
    public static <T> BaseResult<T> success(int status, String msg) {
        BaseResult<T> result = new BaseResult<>();
        result.setStatus(status);
        result.setMessage(msg);
        return result;
    }

    /**
     * @param @param messag
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description 成功时生成result的方法,有返回数据
     * @date 2023/11/08 13:19:12
     */
    public static <T> BaseResult<T> successMessage(String messag) {
        BaseResult<T> result = new BaseResult<>();
        result.setStatus(ResultEnum.SUCCESS.getCode());
        result.setMessage(messag);
        result.setData(null);
        return result;
    }


    /**
     * @param @param status
     * @param msg
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description 失败时生成result的方法
     * @date 2023/11/08 13:19:05
     */
    public static <T> BaseResult<T> error(int status, String msg) {
        BaseResult<T> result = new BaseResult<>();
        result.setStatus(status);
        result.setMessage(msg);
        return result;
    }

    /**
     * @param @param msg
     * @return @return {@link BaseResult }<{@link T }>
     * @author liang-hw
     * @description 失败时生成result的方法
     * @date 2023/11/08 13:18:51
     */
    public static <T> BaseResult<T> error(String msg) {
        BaseResult<T> result = new BaseResult<>();
        result.setStatus(ResultEnum.DETAILS_DATA_BASIC_INFO_ID_IS_EMPTY.getCode());
        result.setMessage(msg);
        return result;
    }
}
